package com.mall.shopping.services;

import com.mall.shopping.IHomepageService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dal.persistence.PanelMapper;
import com.mall.shopping.dto.HomepageResponse;
import com.mall.shopping.dto.PanelDto;
import com.mall.shopping.utils.ExceptionProcessorUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @Classname HomepageServiceImpl
 * @Description /shopping/homepage 查找主页根据类目查找所有商品信息业务逻辑
 * @Date 2021/5/23 22:54
 * @Created by virus
 */
@Service
@Component
@Slf4j
public class HomepageServiceImpl implements IHomepageService {

    @Autowired
    private PanelMapper panelMapper;

    @Override
    public HomepageResponse homepage() {
        HomepageResponse response = new HomepageResponse();
        try {
            Set<PanelDto> panelDtoSet = panelMapper.queryAllProductSortedByPanel();
            response.setCode(ShoppingRetCode.SUCCESS.getCode());
            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
            response.setPanelContentItemDtos(panelDtoSet);
            log.info("/shopping/homepage接口查找主页信息成功");
        } catch (Exception e) {
            log.error("HomepageServiceImpl.homepage occur Exception : " + e);
            ExceptionProcessorUtils.wrapperHandlerException(response, e);
        }
        return response;
    }
}
